/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SimulationConfigPanel.java
 *
 * Created on 08/02/2010, 08:54:57
 */
package org.p2psimulator.gui.panel;

import java.io.File;
import java.util.Calendar;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JTextField;
import org.p2psimulator.config.FileSystemConfig;
import org.p2psimulator.config.OverlayConfig;
import org.p2psimulator.config.ReputationConfig;
import org.p2psimulator.config.SimulationConfig;
import org.p2psimulator.entity.ProtocolType;
import org.p2psimulator.entity.filesystem.FileDistTypes;
import org.p2psimulator.entity.overlaynetwork.OverlayType;
import org.p2psimulator.entity.reputation.ReputationManagerTypes;
import org.p2psimulator.util.dialogs.AlertBox;

/**
 *
 * @author Amorim
 */
public class SimulationConfigPanel extends ConfigPanel {

    /**
     * Creates new form SimulationConfigPanel
     */
    public SimulationConfigPanel() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel10 = new javax.swing.JLabel();
        simulationName = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        totalPeers = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        maxConnections = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        maxTicksField = new javax.swing.JTextField();
        interactionsPerTick = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        ioRate = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        superPeersRate = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        protocolComboBox = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        overlayCombo = new javax.swing.JComboBox();
        jPanel2 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        chartCheckBox = new javax.swing.JCheckBox();
        fileCheckbox = new javax.swing.JCheckBox();
        openButton = new javax.swing.JButton();
        outputDir = new javax.swing.JTextField();

        setMinimumSize(new java.awt.Dimension(175, 550));
        setPreferredSize(new java.awt.Dimension(200, 550));

        jPanel1.setBackground(new java.awt.Color(225, 225, 225));

        jLabel10.setText("Name:");

        simulationName.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        simulationName.setText("P2P Sim");
        simulationName.setPreferredSize(new java.awt.Dimension(40, 17));

        jLabel2.setText(" Peers:");
        jLabel2.setToolTipText("Total of Peers");
        jLabel2.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);

        totalPeers.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        totalPeers.setText("250");
        totalPeers.setPreferredSize(new java.awt.Dimension(25, 20));

        jLabel4.setText("Connectivity:");

        maxConnections.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        maxConnections.setText("4");
        maxConnections.setPreferredSize(new java.awt.Dimension(25, 20));

        jLabel1.setText("Ticks:");

        jLabel3.setText("Int/Tick:");
        jLabel3.setToolTipText("Interactions per Tick");

        maxTicksField.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        maxTicksField.setText("50");
        maxTicksField.setPreferredSize(new java.awt.Dimension(25, 20));

        interactionsPerTick.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        interactionsPerTick.setText("50");
        interactionsPerTick.setPreferredSize(new java.awt.Dimension(25, 20));

        jLabel6.setText("IO Rate:");

        ioRate.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        ioRate.setText("5");
        ioRate.setPreferredSize(new java.awt.Dimension(25, 20));

        jLabel5.setText("SuperPeers:");
        jLabel5.setToolTipText("Percent Rate of SuperPeers (%)");

        superPeersRate.setText("10");
        superPeersRate.setPreferredSize(new java.awt.Dimension(25, 20));

        jLabel11.setText("(%)");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel1)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(maxTicksField, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(interactionsPerTick, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(simulationName, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(totalPeers, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addComponent(superPeersRate, javax.swing.GroupLayout.DEFAULT_SIZE, 52, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel11))
                            .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(34, 34, 34))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(ioRate, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(maxConnections, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel10)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(simulationName, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 12, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(totalPeers, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(superPeersRate, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel11))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(maxTicksField, javax.swing.GroupLayout.DEFAULT_SIZE, 21, Short.MAX_VALUE)
                    .addComponent(interactionsPerTick, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ioRate, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(maxConnections, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        jPanel3.setBackground(new java.awt.Color(225, 225, 225));

        protocolComboBox.setFont(new java.awt.Font("Tahoma", 1, 10)); // NOI18N
        protocolComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Bayesian", "P2PRep", "XRep", "Storm", "EigenTrust", "Superpeer", "Gnutella" }));
        protocolComboBox.setMinimumSize(new java.awt.Dimension(93, 20));
        protocolComboBox.setPreferredSize(new java.awt.Dimension(90, 20));
        protocolComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                protocolComboBoxActionPerformed(evt);
            }
        });

        jLabel9.setBackground(java.awt.Color.white);
        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel9.setText("Protocol:");

        jLabel15.setBackground(java.awt.Color.white);
        jLabel15.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel15.setText("Overlay:");

        overlayCombo.setFont(new java.awt.Font("Dialog", 1, 10)); // NOI18N
        overlayCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Gnutella", "SuperPeer" }));
        overlayCombo.setMinimumSize(new java.awt.Dimension(90, 20));
        overlayCombo.setPreferredSize(new java.awt.Dimension(90, 20));

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(protocolComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(overlayCombo, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 0, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(protocolComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(overlayCombo, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBackground(new java.awt.Color(225, 225, 225));

        jLabel7.setText("Output:");

        jLabel8.setText("Output Dir:");

        chartCheckBox.setSelected(true);
        chartCheckBox.setText("Charts");

        fileCheckbox.setSelected(true);
        fileCheckbox.setText("Files");

        openButton.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        openButton.setText("Abrir");
        openButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openButtonActionPerformed(evt);
            }
        });

        outputDir.setText("/home/users/aamorim/Desktop/P2PRepsim/");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(openButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                        .addComponent(chartCheckBox)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(fileCheckbox))
                    .addComponent(outputDir, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(chartCheckBox, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(fileCheckbox, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(openButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(outputDir, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 0, Short.MAX_VALUE))
                .addContainerGap(23, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(38, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void openButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openButtonActionPerformed
        // TODO add your handling code here:

        JFileChooser fileChooser = new JFileChooser();
        fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

        File chosenFile = null;
        int retValue = fileChooser.showOpenDialog(null);
        if (retValue == JFileChooser.APPROVE_OPTION) {
            chosenFile = fileChooser.getSelectedFile();
        }
        if (chosenFile == null) {
            return;
        }

        if (!chosenFile.isDirectory()) {
            new AlertBox(null, true, "Only directories must be selected!");
            return;
        } else {
            outputDir.setText(chosenFile.getPath());
        }
    }//GEN-LAST:event_openButtonActionPerformed

    private void protocolComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_protocolComboBoxActionPerformed
        // TODO add your handling code here:
        ProtocolType type = getProtocolType();
        if (type == ProtocolType.P2PREP
                || type == ProtocolType.XREP
                || type == ProtocolType.BAYESIAN) {
            overlayCombo.setEnabled(true);
        } else {
            overlayCombo.setEnabled(false);
        }
    }//GEN-LAST:event_protocolComboBoxActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox chartCheckBox;
    private javax.swing.JCheckBox fileCheckbox;
    private javax.swing.JTextField interactionsPerTick;
    private javax.swing.JTextField ioRate;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JTextField maxConnections;
    private javax.swing.JTextField maxTicksField;
    private javax.swing.JButton openButton;
    private javax.swing.JTextField outputDir;
    private javax.swing.JComboBox overlayCombo;
    private javax.swing.JComboBox protocolComboBox;
    private javax.swing.JTextField simulationName;
    private javax.swing.JTextField superPeersRate;
    private javax.swing.JTextField totalPeers;
    // End of variables declaration//GEN-END:variables

    public ProtocolType getProtocolType() {

        String prt = (String) protocolComboBox.getSelectedItem();
        if (prt.equalsIgnoreCase("Storm")) {
            return ProtocolType.STORM;
        } else if (prt.equalsIgnoreCase("XRep")) {
            return ProtocolType.XREP;
        } else if (prt.equalsIgnoreCase("P2PRep")) {
            return ProtocolType.P2PREP;
        } else if (prt.equalsIgnoreCase("EigenTrust")) {
            return ProtocolType.EIGENTRUST;
        } else if (prt.equalsIgnoreCase("Bayesian")) {
            return ProtocolType.BAYESIAN;
        } else if (prt.equalsIgnoreCase("Superpeer")) {
            return ProtocolType.SUPERPEER;
        } else if (prt.equalsIgnoreCase("Gnutella")) {
            return ProtocolType.GNUTELLA;
        }

        throw new IllegalStateException();

    }

    public OverlayType getOverlayType() {

        ProtocolType type = getProtocolType();

        if (type == ProtocolType.P2PREP
                || type == ProtocolType.XREP
                || type == ProtocolType.BAYESIAN) {
            String ort = (String) overlayCombo.getSelectedItem();
            if (ort.equalsIgnoreCase("superpeer")) {
                return OverlayType.SUPERPEER_OVERLAY;
            } else {
                return OverlayType.GNUTELLA_OVERLAY;
            }

        } else if (type == ProtocolType.GNUTELLA) {
            return OverlayType.GNUTELLA_OVERLAY;
        } else if (type == ProtocolType.SUPERPEER) {
            return OverlayType.SUPERPEER_OVERLAY;
        } else if (type == ProtocolType.CHORD
                || type == ProtocolType.STORM) {
            return OverlayType.CHORD_OVERLAY;
        } else if (type == ProtocolType.EIGENTRUST) {
            return OverlayType.HYBRID_OVERLAY;
        } else {
            throw new IllegalStateException();
        }
    }
    
    public ReputationConfig getReputationConfig() {

        ProtocolType type = getProtocolType();
        if (type == ProtocolType.P2PREP) {
            return new ReputationConfig(ReputationManagerTypes.P2PMANAGER);
        } else if (type == ProtocolType.XREP) {
            return new ReputationConfig(ReputationManagerTypes.XREPMANAGER);
        } else if (type == ProtocolType.BAYESIAN) {
            return new ReputationConfig(ReputationManagerTypes.BAYESIANMANAGER);
        } else if (type == ProtocolType.STORM) {
            return new ReputationConfig(ReputationManagerTypes.STORMMANAGER);
        } else if (type == ProtocolType.EIGENTRUST) {
            return new ReputationConfig(ReputationManagerTypes.EIGENMANAGER);
        } else {
            throw new IllegalStateException();
        }

    }

    public OverlayConfig getOverlayConfig() {
        return new OverlayConfig(getOverlayType());

    }
    public SimulationConfig getSimulationConfig() {

        SimulationConfig cfg = new SimulationConfig(
                getMaxTicks(),
                getTotalPeers(),
                getInteractionsPerTick(),
                getMaxConnections(),
                getTotalSuperpeers(),
                "" + getSimulationName());
        cfg.setIOrate(getIoRate());

        return cfg;
    }
    public boolean getChartCheckBox() {
        return chartCheckBox.isSelected();
    }

    public void setChartCheckBox(boolean chartCheckBox) {
        this.chartCheckBox.setSelected(chartCheckBox);
    }

    public boolean getFileCheckbox() {
        return fileCheckbox.isSelected();
    }

    public void setFileCheckbox(boolean fileCheckbox) {
        this.fileCheckbox.setSelected(fileCheckbox);
    }

    

    public int getInteractionsPerTick() {
        try {
            return new Integer(interactionsPerTick.getText());
        } catch (Exception e) {
            mainFrame.getConsoleLogger().addError("Env.: Interactions per tick must have a numeric value");
            return 0;
        }
    }

    public void setInteractionsPerTick(int interactionsPerTick) {
        this.interactionsPerTick.setText("" + interactionsPerTick);
    }

    public int getTotalSuperpeers(){
        try {
            Integer p =  new Integer(superPeersRate.getText());
            Integer ret = (getTotalPeers()*p)/100;
            return ret;
        } catch (Exception e) {
            mainFrame.getConsoleLogger().addError("Env.: IORate must have a numeric value");
            return 0;
        }
    }
    
    public int getIoRate() {
        try {
            return new Integer(ioRate.getText());
        } catch (Exception e) {
            mainFrame.getConsoleLogger().addError("Env.: IORate must have a numeric value");
            return 0;
        }
    }

    public void setIoRate(int ioRate) {
        this.ioRate.setText("" + ioRate);
    }

    public int getMaxConnections() {
        try {
            return new Integer(maxConnections.getText());
        } catch (Exception e) {
            mainFrame.getConsoleLogger().addError("Env.: MaxConnections must have a numeric value");
            return 0;
        }
    }

    public void setMaxConnections(int maxConnections) {
        this.maxConnections.setText("" + maxConnections);
    }

    public int getMaxTicks() {
        try {
            return new Integer(maxTicksField.getText());
        } catch (Exception e) {
            mainFrame.getConsoleLogger().addError("Env.: MaxTicks must have a numeric value");
            return 0;
        }
    }

    public void setMaxTicksField(int maxTicksField) {
        this.maxTicksField.setText("" + maxTicksField);
    }

    public String getOutputDir() {
        return outputDir.getText();
    }

    public void setOutputDir(String outputDir) {
        this.outputDir.setText("" + outputDir);
    }

    public int getTotalPeers() {
        try {
            return new Integer(totalPeers.getText());
        } catch (Exception e) {
            mainFrame.getConsoleLogger().addError("Env.: TotalPeers must have a numeric value");
            return 0;
        }
    }

    public void setTotalPeers(int totalPeers) {
        this.totalPeers.setText("" + totalPeers);
    }

    public String getSimulationName() {
        return simulationName.getText();
    }

    public void setSimulationName(String simulationName) {
        this.simulationName.setText(simulationName);
    }
}
